<template>
  <div>

    <!--    <meta name="referrer" content="no-referrer">-->
    <a-modal
      title="查看详情"
      :width="1200"
      :visible="visible"
      @cancel="handleCancel"
    >
      <div class="table-operator" style="margin-left: 90%;">
        <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0" >
          <a-menu slot="overlay" >
            <a-menu-item key="remove" >
              <remove-goods ref="removeGoods" :goodsIds="selectedRowKeys.join(',')" :data2="data2" @ok="handleOk"/>
            </a-menu-item>
          </a-menu>
          <a-button  >
            批量操作 <a-icon type="down" />
          </a-button>
        </a-dropdown>
        <a-dropdown  v-action:edit v-else-if="selectedRowKeys.length == 0">
          <a-button style="margin-left: 8px">
            批量操作<a-icon type="down" />
          </a-button>
        </a-dropdown>
      </div>


      <template #footer>
        <a-button key="back" @click="handleCancel">确认</a-button>
      </template>
<!--      <a-spin :spinning="confirmLoading">-->
<!--        <div>-->
<!--          <img style="margin-left: 10%; width: 80%; height: 60%" :src="imgUrl" >-->
<!--        </div><br>-->
<!--        <span style="font-weight:bold">商品描述:</span><span style="margin-left: 5%">{{ goods.goodsDesc}}</span>-->
<!--      </a-spin>-->
      <s-table
        v-if="visible"
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns"
        :data="loadData"
        :alert="options.alert"
        :rowSelection="options.rowSelection"
        showPagination="auto"
      >
      <span slot="desc" slot-scope="text, record">
        <template>
          <a @click="showInfo(record)">显示详情</a>
        </template>
      </span>
        <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <remove-goods ref="removeGoods" :goodsIds="String(record.goodsId)" :data2="data2" @ok="handleOk"/>
          <ShowInfo ref="showInfo" @ok="handleOk"/>
          <edit-goods1 ref="editGoods" @ok="handleOk"/>
        </template>
      </span>
<!--        <edit-goods ref="editGoods" @ok="handleOk"/>-->
<!--        <ShowInfo ref="showInfo" @ok="handleOk"/>-->
      </s-table>
    </a-modal>
  </div>

</template>

<script>
import { STable } from '@/components'
import {queryUser} from "@/api/basic/user";
import {queryGoods} from "@/api/basic/goods";
import {queryGoodsByList} from "@/api/basic/goods";
import EditGoods1 from "@/views/basic/modules/goods/EditGoods";
import RemoveGoods from "@/views/basic/modules/goods/RemoveGoods";
import ShowInfo from "@/views/basic/modules/goods/showInfo";

export default {
  name: 'ShowDetail',
  components: {
    STable,
    EditGoods1,
    RemoveGoods,
    ShowInfo,
  },
  data () {
    return {
      // 查询参数
      queryParam: {},
      userInfo:{},
      tt: this.$store.getters.roles.id,
      userId: this.$store.getters.userInfo.id,
      data2: [],
      expandedKeys: [1],
      treeData: [],
      visible: false,
      goods: {},
      imgUrl: '',
      desc: '',
      confirmLoading: false,

      labelCol: {
        xs: { span: 24 },
        sm: { span: 4 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },

      columns: [
        {
          title: '商品编号',
          dataIndex: 'goodsNumber',
          align: 'center'
        },
        {
          title: '商品Id',
          dataIndex: 'goodsId',
          align: 'center'
        },
        {
          title: '商品名称',
          dataIndex: 'goodsName',
          align: 'center'
        },
        {
          title: '创造者',
          dataIndex: 'creator2',
          align: 'center',
        },
        {
          title: '拥有者',
          dataIndex: 'owner2',
          align: 'center',
        },
        {
          title: '商品详情',
          dataIndex: 'desc',
          align: 'center',
          scopedSlots: { customRender: 'desc' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      loadData: parameter => {
        // 统一处理查询参数，便于后端表格DTO用固定参数接收
        const queryJson = { 'queryParam': JSON.stringify(this.queryParam) }
        queryUser(Object.assign(parameter, queryJson))
          .then(res => {
            this.userInfo=res.result.data
            return res.result
          })
        return queryGoodsByList(Object.assign(parameter, queryJson))
          .then(res => {
            const _this=this
            // eslint-disable-next-line no-unused-vars
            this.data2 = res.result.data
            let count = 0
            if (_this.tt === '2') {
              // eslint-disable-next-line no-unused-vars
              this.data2 = res.result.data.filter(i => (i.userId === _this.userId) && (++count))
            }
            const use= this.userInfo
            res.result.data = this.data2
            if(count!==0){
              res.result.totalCount = count
            }
            return res.result
          })
      },
      selectedRowKeys: [],
      selectedRows: [],
      options: {
        alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },

    }
  },
  methods: {
    showDetail (record) {
      this.visible = true
      this.goods = record
      this.queryParam.listId = record.listId
    },
    handleCancel () {
      this.visible = false
    },
    handleOk () {
      this.$refs.table.clearSelected()
      this.$refs.table.refresh(false)
    },
    showInfo (record) {
      // console.log(record)
      this.$refs.showInfo.showInfo(record)
    },
    handleEdit (record) {
      this.$refs.editGoods.edit(record)
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
  }
}
</script>

<style scoped>

</style>
